package com.sgb.kjwl.view.ui.activity.leaseAsk;

import android.content.Context;
import android.content.Intent;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.LinearLayoutManager;
import android.util.Log;
import android.view.View;

import com.google.gson.Gson;
import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityMyAskLeaseQutedBinding;
import com.sgb.kjwl.di.machine.DaggerMachineComponent;
import com.sgb.kjwl.di.machine.MachineModule;
import com.sgb.kjwl.model.entity.lease.MyAskLeaseQutedEntity;
import com.sgb.kjwl.view.ui.adapter.machine.MyAskLeaseQutedAdapter;
import com.sgb.kjwl.viewmodel.machine.MyAskLeaseQutedListModel;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.xrecyclerview.XRecyclerView;

import java.util.List;

import javax.inject.Inject;
//租赁经营-报价列表(查看报价)
@Deprecated
public class MyAskLeaseQutedListActivity extends AppActivity {

    @Inject
    MyAskLeaseQutedListModel model;

    private ActivityMyAskLeaseQutedBinding binding;

    private int page = 1;
    private boolean isLoadMore = false;
    private MyAskLeaseQutedAdapter askLeaseAdapter;
    private String id = "";
    private String categoryType;

    public static void start(Context context,String id,String categoryType){
        Intent intent = new Intent(context,MyAskLeaseQutedListActivity.class);
        intent.putExtra("id",id);
        intent.putExtra("categoryType",categoryType);
        context.startActivity(intent);
    }

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerMachineComponent.builder().appComponent(appComponent)
                .machineModule(new MachineModule(this))
                .build()
                .inject(this);
    }

    @Override
    protected void initView() {
        binding = DataBindingUtil.setContentView(this, R.layout.activity_my_ask_lease_quted);
        binding.include.ivBack.setVisibility(View.VISIBLE);
        binding.include.ivBack.setOnClickListener(view -> finish());
        binding.include.titleView.setText("报价列表");
        binding.include.rightView.setVisibility(View.GONE);

        if (askLeaseAdapter == null) {
            askLeaseAdapter = new MyAskLeaseQutedAdapter(getActivity(), null);
        }
//        DividerItemDecoration divider = new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL);
//        divider.setDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.shape_list_divide));
//        binding.recyclerView.addItemDecoration(divider);
        binding.recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
//        binding.recyclerView.addItemDecoration(new RecyclerCustomDecoration(0, 0, 0, getActivity().getResources().getDimension(R.dimen.dp10), getActivity().getResources().getColor(R.color.color_F5F5F5)));
        binding.recyclerView.setAdapter(askLeaseAdapter);
        binding.recyclerView.setLoadingMoreEnabled(true);
        binding.recyclerView.setLoadingListener(new XRecyclerView.LoadingListener() {
            @Override
            public void onRefresh() {
                getData();
            }

            @Override
            public void onLoadMore() {
                isLoadMore = true;
                page = page+1;
                model.getData(id,categoryType,page);
            }
        });
        askLeaseAdapter.setOnMyAskLeaseQuted(new MyAskLeaseQutedAdapter.OnMyAskLeaseQuted() {
            @Override
            public void getDataList() {
                getData();
            }
        });
    }

    @Override
    protected void init() {
        id = getIntent().getStringExtra("id");
        categoryType = getIntent().getStringExtra("categoryType");
        getData();
    }

    private void getData(){
        isLoadMore = false;
        page = 1;
        model.getData(id,categoryType,page);
    }

    public void showView(List<MyAskLeaseQutedEntity> list) {
        binding.recyclerView.refreshComplete();
        if (isLoadMore) {
            binding.recyclerView.loadMoreComplete();
            if (list.size() > 0) {
                Log.e("tag返回数据",new Gson().toJson(list));
                askLeaseAdapter.addDatas(list);
            } else {
                binding.recyclerView.setLoadingMoreEnabled(false);
            }
            binding.recyclerView.setVisibility(View.VISIBLE);
        } else {
            binding.recyclerView.refreshComplete();
            if (list.size() > 0) {
                Log.e("tag返回数据",new Gson().toJson(list));
                binding.recyclerView.setVisibility(View.VISIBLE);
                binding.emptyView.setVisibility(View.GONE);
                askLeaseAdapter.setDatas(list);
                binding.recyclerView.setLoadingMoreEnabled(true);
            } else {
                askLeaseAdapter.setDatas(null);
                binding.recyclerView.setVisibility(View.GONE);
                binding.emptyView.setVisibility(View.VISIBLE);
            }
        }
    }
}
